package com.ruoyi.project.punch.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.punch.domain.PunchRecord;
import com.ruoyi.project.punch.service.IPunchRecordService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 打卡记录Controller
 * 
 * @author zhf
 * @date 2022-11-05
 */
@RestController
@RequestMapping("/punch/punch")
public class PunchRecordController extends BaseController
{
    @Autowired
    private IPunchRecordService punchRecordService;

    /**
     * 查询打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('punch:punch:list')")
    @GetMapping("/list")
    public TableDataInfo list(PunchRecord punchRecord)
    {
        startPage();
        List<PunchRecord> list = punchRecordService.selectPunchRecordList(punchRecord);
        return getDataTable(list);
    }

    /**
     * 导出打卡记录列表
     */
    @PreAuthorize("@ss.hasPermi('punch:punch:export')")
    @Log(title = "打卡记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PunchRecord punchRecord)
    {
        List<PunchRecord> list = punchRecordService.selectPunchRecordList(punchRecord);
        ExcelUtil<PunchRecord> util = new ExcelUtil<PunchRecord>(PunchRecord.class);
        util.exportExcel(response, list, "打卡记录数据");
    }

    /**
     * 获取打卡记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('punch:punch:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(punchRecordService.selectPunchRecordById(id));
    }

    /**
     * 新增打卡记录
     */
    @PreAuthorize("@ss.hasPermi('punch:punch:add')")
    @Log(title = "打卡记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PunchRecord punchRecord)
    {
        return toAjax(punchRecordService.insertPunchRecord(punchRecord));
    }

    /**
     * 修改打卡记录
     */
    @PreAuthorize("@ss.hasPermi('punch:punch:edit')")
    @Log(title = "打卡记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PunchRecord punchRecord)
    {
        return toAjax(punchRecordService.updatePunchRecord(punchRecord));
    }

    /**
     * 删除打卡记录
     */
    @PreAuthorize("@ss.hasPermi('punch:punch:remove')")
    @Log(title = "打卡记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(punchRecordService.deletePunchRecordByIds(ids));
    }
}
